package com.lap.framework.junit.domain.methods;

import static com.lap.framework.junit.shared.tool.Constant.*;

import com.lap.framework.junit.domain.valueobject.JField;
import com.lap.framework.junit.domain.valueobject.JMethod;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

public class DeleteMethod implements AbstractMethod {

  @Override
  public String execute(JMethod methodInfo) {
    StringBuilder result = new StringBuilder(128);

    result.append(TAB2).append(formatter(PERFORM_PRE, "delete", methodInfo.getUri()));

    String parameter =
        methodInfo.getFields().stream().map(JField::getDataName).collect(Collectors.joining(","));

    if (StringUtils.isNotBlank(parameter)) result.append(", ").append(parameter);

    result.append("))").append(WRAP);
    result.append(TAB6).append(EXPECT_STATUS_IS_OK).append(WRAP);
    result.append(TAB6).append(formatter(EXPECT_JSON, getCode(methodInfo))).append(WRAP);

    return result.toString();
  }
}
